//
//  SCNHomeModels.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/3/13.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import Foundation
import UIKit

class SCNHomeHeaderView: UIView {

    fileprivate var bannerView: HomeBannersView!
    fileprivate var centerLine: UIView!
    fileprivate var investTitle: UIButton!
    fileprivate var incomeTitle: UIButton!
    
    var investMoneyLabel: UILabel!
    
    var incomeMoneyLabel: UILabel!
    
    weak var vc: SCNHomeViewController!
    
    
    
    var banners: Array<SCNHomeBannerModels>? {
        didSet{
            bannerView.banners = banners
            bannerView.headeractionClosures = { [unowned self] (detail) in
                
                self.vc.loadWeb(at: self.vc, url: detail, title: "")

            }
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)

        self.backgroundColor = .white
        
        configurationUI()

    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let supviewWidth = self.center.x
        
        
        bannerView.snp.makeConstraints { (make) in
            make.leading.trailing.top.equalToSuperview()
            make.height.equalTo(200)
        }
        centerLine.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.bottom.equalTo(-15)
            make.size.equalTo(CGSize(width: 1.0, height: 30))
        }
        investTitle.snp.remakeConstraints { (make) in
            make.size.equalTo(CGSize(width: supviewWidth, height: 20))
            make.bottom.equalTo(-30)
            make.leading.equalToSuperview()
        }
        incomeTitle.snp.remakeConstraints { (make) in
            make.size.equalTo(CGSize(width: supviewWidth, height: 20))
            make.bottom.equalTo(-30)
            make.trailing.equalToSuperview()
        }
        investMoneyLabel.snp.remakeConstraints { (make) in
            make.top.equalTo(investTitle.snp.bottom).offset(5)
            make.leading.equalTo(self)
            make.size.equalTo(CGSize(width: supviewWidth, height: 20))

        }
        incomeMoneyLabel.snp.remakeConstraints { (make) in
            make.top.equalTo(incomeTitle.snp.bottom).offset(5)
            make.trailing.equalTo(self)
            make.size.equalTo(CGSize(width: supviewWidth, height: 20))
        }

    }

    deinit {

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func configurationUI() {

        bannerView = HomeBannersView(frame:.zero)
        
        self.addSubview(bannerView)

        
        
        centerLine = UIView()
        centerLine.backgroundColor = .lightGray
        self.addSubview(centerLine)
        
        
        
        investTitle = UIButton(type: .custom)
        investTitle.setTitle("累计投资", for: .normal)
        investTitle.setTitleColor(SCNConstants.colorFromHexValue(0x898989, alpha: 1), for: .normal)
        investTitle.titleLabel?.font = UIFont.systemFont(ofSize: 16.5)
        investTitle.setImage(UIImage(named:"icon-shouye01"), for: .normal)
        investTitle.isEnabled = false
        self.addSubview(investTitle)
        
        
        
        incomeTitle = UIButton(type: .custom)
        incomeTitle.setTitle("累计收益", for: .normal)
        incomeTitle.setTitleColor(SCNConstants.colorFromHexValue(0x898989, alpha: 1), for: .normal)
        incomeTitle.titleLabel?.font = UIFont.systemFont(ofSize: 16.5)
        incomeTitle.setImage(UIImage(named:"icon-shouye02"), for: .normal)
        incomeTitle.isEnabled = false
        self.addSubview(incomeTitle)
        
        

        
        investMoneyLabel = UILabel()
        investMoneyLabel.font = UIFont.systemFont(ofSize: 19.0)
        investMoneyLabel.textAlignment = .center
        investMoneyLabel.text = "- - 元"
        self.addSubview(investMoneyLabel)
        
        
        
        incomeMoneyLabel = UILabel()
        incomeMoneyLabel.font = UIFont.systemFont(ofSize: 19.0)
        incomeMoneyLabel.textAlignment = .center
        incomeMoneyLabel.text = "- - 元"
        self.addSubview(incomeMoneyLabel)
        
        
    }

    
}



